﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class my_data1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ctpDataContext db = new ctpDataContext();
        int no = int.Parse(Request["no"]);
        //int no = 1;

        string result = "",nickname;




        //bind user subscribe cities

        var si=from p in db.my_citiport_subscribes
               join q in db.my_citiport_mines on p.subscribe_ct_no equals q.no
               join i in db.users on q.userno equals i.no
               join j in db.ct_profiles on q.ct_no equals j.no
               where p.userno==no
               orderby p.addtime descending
               select new
               {
                   title = j.title.Trim().Replace(",", ""),
                   j.no,
                   q.recommend,
                   main_pic_fn = i.profile_picture.Trim(),
                   nickname=i.nickname.Trim().Replace(",",""),
                   q.userno

               };

        foreach (var m in si)
        {
            if (result != "") result += ",";

            nickname = m.nickname;

            if (nickname.Substring(nickname.Length - 1, 1) == "s")
                nickname += "'";
            else
                nickname += "'s";

            result += nickname + ",";
            result += m.title + ",";
            result += m.recommend.ToString() + ",";
            result += "../user_imgs/1/" + m.main_pic_fn + ",";

            if (nickname=="Kelvin's")
            {
                result += "1,";
            }
            else
            {
                result += "0,";
            }
            result += m.no.ToString();
            result += ","+m.userno.ToString();

        }


        //bind user cities
        var mi = from p in db.my_citiport_mines
                 join q in db.ct_profiles on p.ct_no equals q.no
                 where p.userno == no
                 orderby p.addtime descending
                 select new
                 {
                     title = q.title.Trim().Replace(",", ""),
                     q.no,
                     p.recommend,
                     main_pic_fn = q.main_pic_fn.Trim()

                 };


        user myuser = db.users.Single(p => p.no == no);
        nickname = myuser.nickname.Trim().Replace(",", "");

        if (nickname.Substring(nickname.Length - 1, 1) == "s")
            nickname += "'";
        else
            nickname += "'s";

        foreach (var m in mi)
        {
            if (result != "") result += ",";

            result += nickname + ",";
            result += m.title + ",";
            result += m.recommend.ToString() + ",";
            result += "../city_imgs/1/" + m.main_pic_fn + ",";

            if (m.no == 17)
            {
                result += "1,";
            }
            else
            {
                result += "0,";
            }
            result += m.no.ToString();
            result+=","+no.ToString();

        }

        Response.Write(result);

    }
}
